/**
 * @file    diagnosis.c
 * @brief   故障诊断
 * @author  Liuwei
 * @version 1.0.1
 * @date    2023-04-18
 * 
 * @copyright Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD
 * 
 * @par 修改日志:
 * <table>
 * <tr><th>Date       <th>Version   <th>Author   <th>Description
 * <tr><td>2023-04-18 <td>1.0.1     <td>Liuwei   <td>首次创建
 * </table>
 */

/* includes ------------------------------------------------------------------*/
#include "diagnosis.h"
#include "mcu_type.h"
/* macro/define --------------------------------------------------------------*/

/* typedef -------------------------------------------------------------------*/
/* local functions -----------------------------------------------------------*/

/* static variables ----------------------------------------------------------*/
static diag_alm_type diag_alm_msg = {0};
static diag_prp_type diag_prp_msg = {0};
/* global variables ----------------------------------------------------------*/

/** ------------------------------------------------------------------------- *
  *                             Global function
 ** ------------------------------------------------------------------------- */
/**
 * @brief  获取某个告警状态
 * @param  alm_id: 告警ID
 * @return 
*/
uint8_t diag_get_alarm(alm_id_type alm_id)
{
    if((1 << alm_id) & diag_alm_msg.alm_word)
        return TRUE;
    else
        return FALSE;
}

/**
 * @brief  设置某个告警状态
 * @param  alm_id : 告警状态
 * @return uint8_t ;
 */
void diag_set_alarm(alm_id_type alm_id , uint8_t state)
{
    if(state)
        diag_alm_msg.alm_word |= (1 << alm_id);
    else
        diag_alm_msg.alm_word &= ~(1 << alm_id);
}

/**
 * @brief  获取所有告警信息
 * @return uint32_t 
 */
uint32_t diag_get_all_alarm(void)
{
    return diag_alm_msg.alm_word;
}

/**
 * @brief  获取某个保护状态
 * @param  prp_id: 保护ID
 * @return 
*/
uint8_t diag_get_prp(prp_id_type prp_id)
{
    if((1 << prp_id) & diag_prp_msg.prp_word)
        return TRUE;
    else
        return FALSE;
}

/**
 * @brief  设置某个保护标志位
 * @param  prp_id
 * @return uint8_t 
 */
void diag_set_prp(prp_id_type prp_id ,uint8_t state)
{
    if(state)
        diag_prp_msg.prp_word |= (1 << prp_id);
    else 
        diag_prp_msg.prp_word &= ~(1 << prp_id);
}

/**
 * @brief  获取所有保护状态
 * @return uint32_t 保护信息
 */
uint32_t diag_get_all_prp(void)
{
    return diag_prp_msg.prp_word;
}
/** ------------------------------------------------------------------------- *
  *                              Local function
 ** ------------------------------------------------------------------------- */
 
/********** Copyright (c) 2023 JBD-Energy Storage Technology Co. LTD *********/


